/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package phan.connection;



import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;



/**
 *
 * @author PHAN
 */
public class insProcess extends HttpServlet{

  private ServletConfig config;

  public void init(ServletConfig config)
    throws ServletException{
     this.config=config;
     }

  public void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException,IOException{

    PrintWriter out = response.getWriter();
  //  String connectionURL = "jdbc:mysql://localhost:3306/web";
    Connection connection=null;
    ResultSet rs;
    String userName=new String("");
    String passwrd=new String("");
    response.setContentType("text/html");
    try {
       // Load the database driver
      Class.forName("com.mysql.jdbc.Driver");
      // Get a Connection to the database
      connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/web","root","19091982");
      //Add the data into the database
      String sql = "select user_login,user_password from user_table";
      Statement s = connection.createStatement();
      s.executeQuery (sql);
      rs = s.getResultSet();
      while (rs.next ()){
        userName=rs.getString("user_login");
        passwrd=rs.getString("user_password");
      }
      rs.close ();
      s.close ();
      }catch(Exception e){
      System.out.println("Exception is ;"+e);
      }
      if(userName.equals(request.getParameter("user"))
             && passwrd.equals(request.getParameter("pass"))){
        out.println("BIENVENUE "+userName+"login in at" + new java.util.Date());
        response.sendRedirect("index.jsp");


      }
      else{
        out.println("Please enter correct username and password");
        response.sendRedirect("AuthenticLogin.jsp");
      }
  }
}